<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/template/template.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
	    <link rel="stylesheet" href="/resources/bootstrap/css/bootstrap-datetimepicker.min.css" />
		<link rel="stylesheet"
			href="/resources/plugins/datatables/dataTables.bootstrap.css" />
<style>
		
</style>
	</ui:define>
	<ui:define name="content">
	     <p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
			<p:commandButton value="是" type="button"
				styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
			<p:commandButton value="否" type="button"
				styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
		</p:confirmDialog>
		<div class='full-center-content-scroll-noheader'>
		  <div class="nav-tabs-custom">
			<h:form id="form">
				<p:growl id="msgs" showDetail="true" />
				<!-- <div class="box box-solid with-border"> -->
			<div class="tab-content no-padding">
			  <div class="chart tab-pane active" id="stations" style="position: relative">
				<div class="box box-primary box-solid with-border">
								<div class="box-header"  id="queryDiv"  >
									<h3    class="box-title">选择查询条件【上次统计时间：<p:outputLabel  id="updateTime" value="#{primaryDeviceCountController.updateTime}"></p:outputLabel>】
									</h3>
									<div class="box-tools pull-right">
										<button class="btn btn-default btn-sm" data-widget="collapse">
											<i class="fa fa-minus"></i>
										</button>
									</div>
								</div>
					   <div class="box-body"  id="query">
								    <p:commandButton   id="editBtn"  value="编辑" style="float: left;" icon="ui-icon-document" 
								    update=":editForm:editPanel" 
									 disabled="#{primaryDeviceCountController.selectedDto == null}" 
									 onclick="PF('editDialog').show()" 	 />
									 <div style="float: left; height: 30px; line-height: 30px; margin-left: 10px;">
									 	<p:selectManyCheckbox id="box"  value="#{primaryDeviceCountController.selectedVoltage}" >
									       <f:selectItem itemLabel="35kV" itemValue="35" />
											<f:selectItem itemLabel="110kV" itemValue="110" />
											<f:selectItem itemLabel="220kV" itemValue="220" />
											<f:selectItem itemLabel="500kV" itemValue="500" />
											<f:selectItem itemLabel="全部" itemValue="全部" />
									    </p:selectManyCheckbox>
									</div>
								  <h:selectOneMenu id="unit" value="#{primaryDeviceCountController.unitType}"
									style="width:160px;height:30px"  >
									<f:selectItem itemLabel="调管范围" itemValue="0" />
									<f:selectItem itemLabel="检修范围" itemValue="1" />
							      </h:selectOneMenu>
								    <p:remoteCommand name="changeYearAnalysis" actionListener="#{primaryDeviceCountController.changeYear}" />
									<p:outputLabel value="年份:"   style="padding-left:5px;"/>
        							<input type="text" id="yearAnalysis" onchange="chaneYearAnalysis()" style="width:60px;margin-left:5px;text-align:center"/>
									<p:commandButton value="查询" id="query2"   
									 icon="ui-icon-search" update = ":form:deviceDataTable  :form:updateTime"
										actionListener="#{primaryDeviceCountController.query}"
										style="margin-left:10px;">
									</p:commandButton>
									<p:commandButton icon="ui-icon-refresh" value="重置" 
										actionListener="#{primaryDeviceCountController.resetQuery}"
										style="margin-left:5px;"
										update=":form:editBtn  :form:deviceDataTable  box unit"/>
									<p:commandButton id="reCountBtn"  style="float: right;margin-right:10px;" 
									  value="实时统计"  actionListener="#{primaryDeviceCountController.reStatistic}" 
        								icon="fa fa-refresh" update=":form:editBtn  :form:deviceDataTable  :form:updateTime"    >
										<p:confirm header="提示" message="重新统计会覆盖当前已存在的数据， 将从cim数据中进行统计。该操作不可回退确定要继续执行吗？" icon="ui-icon-alert" />
        							</p:commandButton>
        							<p:selectBooleanCheckbox    style="float: right;margin-top:7px;color:blue" itemLabel="是否覆盖修改数据" value="#{primaryDeviceCountController.reStatisticStatus}" />
						  </div>
						</div>
				<div class="box box-primary box-solid with-border" style="text-align: center">
				<p:dataTable style="text-align:center" value="#{primaryDeviceCountController.statisticTableDto}" selectionMode="single"
								id="deviceDataTable" var="item" emptyMessage="无记录"  scrollable="true"  
								 selection="#{primaryDeviceCountController.selectedDto}" rowKey="#{item.id}">
								<p:ajax   update = " :form:editBtn   "  event="rowSelect" listener="#{primaryDeviceCountController.onRowSelect}" />   
								<p:column headerText="单位"   groupRow="true" style="text-align:center" >
									<h:outputLabel value="#{item.unit}" />
								</p:column>
								<p:column headerText="电压等级(kV)"  style="text-align:center">
									<h:outputLabel value="#{item.voltageLevel}"  />
								</p:column>
								<p:column headerText="厂站数量" style="text-align:center">
									<h:outputLabel value="#{item.stationCount}" />
								</p:column>
								<p:column headerText="母线数量"  style="text-align:center">
									<h:outputLabel value="#{item.busbarsectionCount}" />
								</p:column>
								<p:column headerText="线路数量"  style="text-align:center">
									<h:outputLabel value="#{item.lineCount}" />
								</p:column>
								<p:column headerText="变压器数量"  style="text-align:center">
									<h:outputLabel value="#{item.powerTransformerCount}" />
								</p:column>
								<p:column headerText="断路器数量"  style="text-align:center">
									<h:outputLabel value="#{item.breakerCount}" />
								</p:column>
								<p:column headerText="发电机数量"  style="text-align:center">
									<h:outputLabel value="#{item.generatorCount}" />
								</p:column>
								<p:column headerText="高抗数量"  style="text-align:center">
									<h:outputLabel value="" />
								</p:column>
								<p:column headerText="串补数量"  style="text-align:center">
									<h:outputLabel value="" />
								</p:column>
							    <p:column  headerText = "汇总"  style="text-align:center">
							         <h:outputLabel   value="#{item.summary}"/>
							    </p:column>
								<p:columnGroup type="footer">
							            <p:row style="font-weight:bold">
							                 <p:column colspan = "2"  style="text-align:right;background-color:#3C8DBC;color:#fff;width:40px;" footerText="汇总:" />
							                  <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{primaryDeviceCountController.getSummary('0')}" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{primaryDeviceCountController.getSummary('1')}" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{primaryDeviceCountController.getSummary('2')}" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{primaryDeviceCountController.getSummary('3')}" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{primaryDeviceCountController.getSummary('4')}" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{primaryDeviceCountController.getSummary('5')}" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="" />
							                <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="" />
							                 <p:column style="text-align:center;background-color:#3C8DBC;color:#fff" footerText="#{primaryDeviceCountController.getSummary('8')}" />
							            </p:row>
							        </p:columnGroup>
							</p:dataTable>
					</div>
				  </div>
				</div>
			</h:form>
			<h:form id="editForm">
				<p:dialog id="editDialog" widgetVar="editDialog" modal="true" header="编辑统计参数" width="310" height="450">
							<p:toolbar>
								<f:facet name="left">
									<p:commandButton value="保存"  
										update=":form:deviceDataTable" oncomplete="PF('editDialog').hide()"/>
									<p:commandButton value="取消" onclick="PF('editDialog').hide()"/>
								</f:facet>
							</p:toolbar>
							<p:panelGrid columns="2" id="editPanel">
								<p:outputLabel value="单位"/>
								<p:inputText value="#{primaryDeviceCountController.selectedDto.unit}" readonly="true" />
								<p:outputLabel value="变电站数量"/>
								<p:inputText value="#{primaryDeviceCountController.selectedDto.stationCount}" >
								<p:ajax  event = "change"  listener = "#{primaryDeviceCountController.onChange('0')}"   />
								</p:inputText>
								<p:outputLabel value="母线数量"/>
								<p:inputText value="#{primaryDeviceCountController.selectedDto.busbarsectionCount}" >
								<p:ajax  event = "change"  listener = "#{primaryDeviceCountController.onChange('1')}"   />
								</p:inputText>
								<p:outputLabel value="线路数量"/>
								<p:inputText value="#{primaryDeviceCountController.selectedDto.lineCount}" >
								<p:ajax  event = "change"  listener = "#{primaryDeviceCountController.onChange('2')}"   />
								</p:inputText>
								<p:outputLabel value="变压器数量"/>
								<p:inputText value="#{primaryDeviceCountController.selectedDto.powerTransformerCount}"  >
								<p:ajax  event = "change"  listener = "#{primaryDeviceCountController.onChange('3')}"   />
								</p:inputText>
								<p:outputLabel value="断路器数量" />
								<p:inputText value="#{primaryDeviceCountController.selectedDto.breakerCount}"   >
								<p:ajax  event = "change"  listener = "#{primaryDeviceCountController.onChange('4')}"   />
								</p:inputText>
								<p:outputLabel value="发电机数量" />
								<p:inputText value="#{primaryDeviceCountController.selectedDto.generatorCount}">
								<p:ajax  event = "change"  listener = "#{primaryDeviceCountController.onChange('5')}"   />
			 					</p:inputText>
								<p:outputLabel value="高抗数量" />
								<p:inputText value=" ">
								</p:inputText>
								<p:outputLabel value="串补数量" />
								<p:inputText value=" ">
								</p:inputText>
							</p:panelGrid>
					</p:dialog>
			</h:form>
		    </div>
		</div>
	</ui:define>
	<ui:define name="contentend">
	<script src="/resources/bootstrap/js/bootstrap-datetimepicker.min.js" />
	<script src="/ui/map/dialog/riskAlarmDialog/searchAlarmMsgDlg.js?version=1.0" />
		<script>
		
		$(function(){
			var d = new Date();
			var currentYear=d.getFullYear();
			$("#year").val(currentYear);
			$('#year').datetimepicker({
				startView: 4,
				minView:4,
				autoclose : true,
				format : 'yyyy'
			});
			
			$("#yearAnalysis").val(currentYear);
			$('#yearAnalysis').datetimepicker({
				startView: 4,
				minView:4,
				autoclose : true,
				format : 'yyyy'
			});
			
		});

		
		function chaneYearAnalysis(){
			var year=$("#yearAnalysis").val();
			changeYearAnalysis([ {
				name : 'yearAnalysis',
				value : year
			}]);
		}
			
		</script>
	</ui:define>
</ui:composition>
